package com.kurumi.medical.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kurumi.medical.datasource.TargetDataSource;
import com.kurumi.medical.mapper.HolidayMapper;
import com.kurumi.medical.pojo.HospitalHoliday;
import com.kurumi.medical.service.HolidayService;
import com.kurumi.medical.util.Result;

@Service
public class HolidayServiceImpl implements HolidayService{
	
	@Autowired
	private HolidayMapper holidayMapper;

	@Override
	@TargetDataSource(name="ds1")
	public List<HospitalHoliday> getHolidays() {
		return holidayMapper.getHolidays();
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public int insert(HospitalHoliday hospitalHoliday) {
		return holidayMapper.insert(hospitalHoliday);
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public int updateByPrimaryKey(HospitalHoliday hospitalHoliday) {
		return holidayMapper.updateByPrimaryKey(hospitalHoliday);
	}

	@Override
	@Transactional
	@TargetDataSource(name="ds1")
	public Result setHoliday(Date date, Integer id) {
		Result result = new Result(false,"");
		HospitalHoliday bean = null;
		int count = 0;
		if(id!=null){
			 count = holidayMapper.deleteById(id);
		}else{
			 bean = new HospitalHoliday();
			bean.setHolidaysDate(date);
			bean.setHospitalId(1);
			count = holidayMapper.insert(bean);
		}
		if(count>0){
			result.setSuccess(true);
			if(bean != null){
				result.setMsg(bean.getId().toString());
			}else{
				result.setMsg("");
			}
			
		}
		return result;
	}

}
